/**
 * Copyright (C), 2015-2019, XXX有限公司
 * FileName: SchedulingTest
 * Author:   pc
 * Date:     2019/9/6 13:45
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.example.rabbitmqdemo.controller;


import com.example.rabbitmqdemo.job.Job;
import com.example.rabbitmqdemo.service.QuartzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;

/**
 * 〈功能：〉<br>
 * 〈Springboot自带的定时器Scheduling测试〉
 *
 * @author liuhaoran
 * @create 2019/9/6 13:45
 * @since 1.0.0
 */
@EnableScheduling
@Component
public class SchedulingTest {
	@Autowired
	QuartzService quartzService;

	/**
	 * 最简单的定时任务
	 *
	 * @throws InterruptedException
	 */
	@Scheduled(cron = "0/5 * * * * ? ")
	public void reportCurrentTimeCron() throws InterruptedException {
		//System.out.println("最简单的定时任务！");
	}
	@RequestMapping("/testqua")
	public void run(String... args) throws Exception {
		HashMap<String, Object> map = new HashMap<>();
		map.put("name", 1);
		quartzService.deleteJob("job", "test");
		quartzService.addJob(Job.class, "job", "test", "0 * * * * ?", map);

		map.put("name", 2);
		quartzService.deleteJob("job2", "test");
		quartzService.addJob(Job.class, "job2", "test", "10 * * * * ?", map);

		map.put("name", 3);
		quartzService.deleteJob("job3", "test2");
		quartzService.addJob(Job.class, "job3", "test2", "15 * * * * ?", map);

	}
}